package com.jyw.business.obstacles.controller;

import com.github.pagehelper.PageHelper;
import com.jyw.business.obstacles.domain.dto.web.OrderAllPageDto;
import com.jyw.business.obstacles.domain.dto.web.OrderRejectUpdDto;
import com.jyw.business.obstacles.domain.dto.web.WorkOrderPageDto;
import com.jyw.business.obstacles.domain.vo.web.OrderAllPageVO;
import com.jyw.business.obstacles.domain.vo.web.ProcessedPageVO;
import com.jyw.business.obstacles.domain.vo.web.WorkOrderPageVO;
import com.jyw.business.obstacles.service.IObsOrderFaultService;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author w_q
 * @date 2023/8/1713:47
 * @Description:
 */
@Api(tags = "工单")
@RestController
@RequestMapping("/obstacles/order")
public class ObsMyOrderController extends BaseController {


    @Autowired
    private IObsOrderFaultService iObsOrderFaultService;


    @PreAuthorize("@ss.hasPermi('obstacles:order:pagePending')")
    @PostMapping("/pagePending")
    @ApiOperation("待审核工单")
    public TableDataInfo<WorkOrderPageVO> pageWorkOrder(@Validated @RequestBody WorkOrderPageDto workOrderPageDto) {
        startPage();
        List<WorkOrderPageVO> list = iObsOrderFaultService.pageWorkOrder(workOrderPageDto);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('obstacles:order:pageProcessed')")
    @PostMapping("/pageProcessed")
    @ApiOperation("审核过的工单")
    public TableDataInfo<ProcessedPageVO> pageProcessed(@Validated @RequestBody WorkOrderPageDto workOrderPageDto) {
        startPage();
        List<ProcessedPageVO> list = iObsOrderFaultService.pageProcessed(workOrderPageDto);
        return getDataTable(list);
    }


    @GetMapping("/enact")
    @PreAuthorize("@ss.hasPermi('obstacles:mine:order:receive')")
    @ApiOperation("通过")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderNums", value = "orderNums", required = true),
    })
    public CommonResult enact(String orderNums) {
        iObsOrderFaultService.enact(orderNums);
        return CommonResult.success();
    }

    @PostMapping("/reject")
    @PreAuthorize("@ss.hasPermi('obstacles:mine:order:reject')")
    @ApiOperation("驳回")
    public CommonResult reject(@Validated @RequestBody OrderRejectUpdDto dto) {
        iObsOrderFaultService.reject(dto);
        return CommonResult.success();
    }

    @PreAuthorize("@ss.hasPermi('obstacles:order:pageAllOrder')")
    @PostMapping("/pageAllOrder")
    @ApiOperation("全部工单")
    public TableDataInfo<OrderAllPageVO> pageWholeOrder(@RequestBody OrderAllPageDto dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize()).reasonable(true);
        List<OrderAllPageVO> list = iObsOrderFaultService.pageWholeOrder(dto);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('obstacles:order:exportOrder')")
    @PostMapping("/exportOrder")
    @ApiOperation("导出工单")
    public void exportProduct(HttpServletResponse response, @Validated @RequestBody OrderAllPageDto dto) {
        iObsOrderFaultService.exportProduct(response, dto);
    }


}
